using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace WPCoco
{
    /// <summary>
    /// Structure for hold information about an rectangle using float values
    /// </summary>
    public struct RectangleF
    {
        public RectangleF(float x, float y, float width, float height)
        {
            X = x; Y = y; Width = width; Height = height;
        }

        public float X;

        public float Y;

        public float Width;

        public float Height;

        /// <summary>
        /// Return true if the rectangle contain other rectangle
        /// </summary>
        /// <param name="rectangle">Rectangle to test</param>
        /// <returns></returns>
        public bool InterceptWith(RectangleF rectangle) 
        {
            if (X + Width < rectangle.X) return false;
            if (X > rectangle.X + rectangle.Width) return false;
            if (Y + Height < rectangle.Y) return false;
            if (Y > rectangle.Y + rectangle.Height) return false;
            return true;
        }

        /// <summary>
        /// Return true if the rectangle contain a point
        /// </summary>
        /// <param name="point">Point to test</param>
        public bool Contains(Vector2 point) 
        {
            if (X + Width < point.X) return false;
            if (X > point.X) return false;
            if (Y + Height < point.Y) return false;
            if (Y > point.Y) return false;
            return true;
        }

        /// <summary>
        /// Returns true if the rectangles is empty
        /// </summary>
        public bool IsEmpty 
        {
            get 
            {
                return Width == 0 && Height == 0;
            }
        }

        public override string ToString()
        {
            return string.Format("X = {0}, Y = {1}, Width = {2}, Height = {3}", X, Y, Width, Height);
        }

        public Rectangle ToRectangle() 
        {
            return new Rectangle((int)X, (int)Y, (int)Width, (int)Height);
        }
    
        public static RectangleF GetRectangle(Vector2 a, Vector2 b)
        {
            return new RectangleF(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y), Math.Abs(a.X - b.X), Math.Abs(a.Y - b.Y));
        }
    }
}
